package dao

import (
	"fmt"
	"task-server-gin/client"
	"task-server-gin/model"
)

type MysqlDao struct {
}

func (dao MysqlDao) GetSingleTask() (*model.GormSingleTask, error) {
	fmt.Println("GetSingleTask")
	task := client.MysqlTask{}.GetFresh()
	fmt.Println("task =", task)
	return task, nil
}

func (dao MysqlDao) UpdateTaskStateById(jobId string) *model.GormSingleTask {
	task := client.MysqlTask{}.UpdateTaskStateById(jobId)
	if task != nil {
		// 更新成功
		fmt.Println("update task state success!")
		return task
	}
	fmt.Println("not found the task with state")
	return nil

}

func (dao MysqlDao) InsertDownloadRecord(url string) (*model.DownloadRecord, error) {

	result, err := client.MysqlTask{}.InsertDownloadRecord(url)
	return result, err

}

func (dao MysqlDao) GetDownloadRecord(url string) (bool, error) {
	// result : true 没有查询到结果， false 查询到结果，已经有记录了
	result, err := client.MysqlTask{}.GetDownloadRecord(url)
	return result, err

}

func (dao MysqlDao) InsertVideoInfo(item *model.VideoInfo) (bool, error) {
	result, err := client.MysqlTask{}.InsertVideoInfo(item)
	return result, err
}
